//
//  AppDelegate_iPad.m
//  PokerPlus
//
//  Created by sunrui-MacBook on 11-7-27.
//  Copyright 2011 139.ME. All rights reserved.
//

#import "AppDelegate_iPad.h"
#import "RootViewController_iPad.h"

@implementation AppDelegate_iPad

@synthesize window,viewController;


#pragma mark -
#pragma mark Application lifecycle


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    // Override point for customization after application launch.
    [self.window addSubview:viewController.view];
    [self.window makeKeyAndVisible];
	
	NSLog(@"当前语言是:%@",[[NSLocale preferredLanguages] objectAtIndex:0]);
	 
	
    return YES;
}

- (UIView *)rootView{
	return viewController.view;
}

-(void)rsEnterRoom:(SocketEngine *)socket withResult:(BOOL)result{
	if (result) {
		
		[viewController EnterRoom:NewUpdate([socket ReadData:sizeof(UpdateDesk)])];
	}
}

-(void)rsSetUserInfo:(SocketEngine *)socket{
	
	[viewController SetUsrInfo:NewUsrInfo([socket ReadData:sizeof(UsrInfo)])];
}

-(void)rsSetRoomSort:(SocketEngine *)socket{
	
	int num = [socket ReadInt];
	RoomSort rs = NewRoomSort([socket ReadData:sizeof(RoomSortInfo)], num);
	[viewController SetRoomSort:rs];
}

-(void)rsSetRoomList:(SocketEngine *)socket{
	
	int num = [socket ReadInt];
	NSLog(@"numberis:%d",num);
	
	RoomList rl = NewRoomList([socket ReadData:sizeof(RoomInfo)], num);
	[viewController SetRoomList:rl];
}

-(void)rsRefreshGameInfo:(SocketEngine *)socket{
	[viewController RoomRefresh:NewUpdate([socket ReadData:sizeof(UpdateDesk)])];
}



- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
	//[viewController.view addSubview:viewController.glView];
	//enterBackground = YES;
	[viewController EnterBackGround];
	[[NSNotificationCenter defaultCenter] postNotificationName:@"EnterBackground" object:nil];
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive.
     */
	
	[viewController ConnectServer];
}


- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.	 
     */
}


-(void) applicationDidEnterBackground:(UIApplication*)application {
	NSLog(@"will EnterBackground");
}

-(void) applicationWillEnterForeground:(UIApplication*)application {
	NSLog(@"will EnterForeground");

}

#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}


- (void)dealloc {
    [window release];
    [super dealloc];
}


@end
